package com.szbber.commen.utils

import android.content.Context
import android.content.SharedPreferences

/**
 * @author: Administrator
 * @date: 2022/4/18
 */
object PreferUtil{


    private var mPrefer: SharedPreferences? = null
    private const val APP_NAME = "com.szbber.medical"
    private const val DEVICETYPE = "devicetype"
    private const val ServiceIP = "ServiceIP"

    fun setServiceIP(fag: String) {
        putString(DEVICETYPE, fag)
    }

    fun getServiceIP(): String? {
        return getString(DEVICETYPE, "122.112.148.38:8888")
    }

    fun setDeviceType(fag: Int) {
        putInt(DEVICETYPE, fag)
    }

    fun getDeviceType(): Int? {
        return getInt(DEVICETYPE, 0)
    }

    fun init(ctx: Context) {
        mPrefer = ctx.getSharedPreferences(APP_NAME, Context.MODE_PRIVATE or Context.MODE_PRIVATE)
        mPrefer?.edit()?.commit()
    }

    fun getString(key: String?, defValue: String?): String? {
        return mPrefer?.getString(key, defValue)
    }

    fun getInt(key: String?, defValue: Int): Int? {
        return mPrefer?.getInt(key, defValue)
    }

    fun getBoolean(key: String?, defValue: Boolean): Boolean? {
        return mPrefer?.getBoolean(key, defValue)
    }

    fun putString(key: String?, value: String?) {
        mPrefer?.edit()?.putString(key, value)?.commit()
    }

    fun putInt(key: String?, value: Int) {
        mPrefer?.edit()?.putInt(key, value)?.commit()
    }

    fun putBoolean(key: String?, value: Boolean) {
        mPrefer?.edit()?.putBoolean(key, value)?.commit()
    }

    fun putLong(key: String?, value: Long) {
        mPrefer?.edit()?.putLong(key, value)?.commit()
    }

    fun getLong(key: String?, defValue: Long): Long? {
        return mPrefer?.getLong(key, defValue)
    }

    fun removeKey(key: String?) {
        mPrefer?.edit()?.remove(key)?.commit()
    }


}